<?php

namespace app\user\controller;

use app\user\controller\Auth;

class Index extends Auth
{

    //需验证方法集
    protected $is_check_login = ['login', 'register'];

    // 页面
    public function inlet()
    {
        $cof = $this->getCof('index');
        // 访问页面
        $IndexPage = input('IndexPage') == null ? 'index' : input('IndexPage');
        $info = db('v1_user')->where('user_name',  session('username'))->join('v1_user_info', 'v1_user.user_id=v1_user_info.user_id')->find();
        $this->assign('IndexPage', $IndexPage);
        $this->assign([
            'cof'  => $cof,
            'info' => $info
        ]);
        // 判断方法是否存在
        if (method_exists($this, $IndexPage)) {
            return $this->$IndexPage();
        } else {
            return view("define/" . input('IndexPage'));
        }
    }

    // 收藏记录
    public function favs()
    {
        $field = 'collect_id as id,collect_title as title,collect_pic as pic,collect_url as url,collect_type as type,DATE_FORMAT(collect_time, "%Y-%m-%d %H:%s") as time';
        $data = db('v1_collect')->where('user_id', session('userinfo')['user_id'])->field($field)->select();
        $this->assign([
            'data'  => $data
        ]);
        return view("define/favs");
    }

    // 播放记录
    public function plays()
    {
        $field = 'see_id as id,see_title as title,see_pic as pic,see_url as url,see_type as type,see_count as count,DATE_FORMAT(see_time, "%Y-%m-%d %H:%s") as time';
        $data = db('v1_see_record')->where('user_id', session('userinfo')['user_id'])->field($field)->select();
        $this->assign([
            'data'  => $data
        ]);
        return view("define/plays");
    }


    // 用户首页
    public function index()
    {
        return view("define/index");
    }

    // 基本信息
    public function info()
    {
        return view("define/info");
    }

    // 修改信息
    public function infoedit()
    {
        return view("define/infoedit");
    }

    // 我的权限
    public function popedom()
    {
        return view("define/popedom");
    }

    // 注销登录
    public function logout()
    {
        session(null);
        return $this->success("注销成功", "/user/login.html");
    }

    // 初始化页面信息
    public function getCof($page, $info = [])
    {
        // 网站配置信息
        $webset = getConfig("webset");
        // 默认SEO信息
        $seoset = getConfig("seoset");
        // 提示信息
        $tipsset = getConfig("tipsset");

        $cof = [
            "title" => $webset['title'] . " - " . $seoset['seotitle'],
            "keywords" => $seoset['keywords'],
            "description" => $seoset['description'],
            'logo' => $webset['logo'],
            'copyright' => $webset['copyright'],
            "census" => $webset['census'],
        ];
        return $cof;
    }
}
